package com.databaseconnectionmobilapi.controller;


import com.databaseconnectionmobilapi.domain.dto.*;
import com.databaseconnectionmobilapi.service.ConnectionDbService;
import com.databaseconnectionmobilapi.util.result.RestResult;
import lombok.AllArgsConstructor;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fall
 * @since 2022-01-17
 */
@RestController
@AllArgsConstructor
public class ConnectionDbController {
    private ConnectionDbService connectionDbService;

    @PostMapping("/all/connection")
    public RestResult selectAllConnection(@RequestHeader("token") String token, @RequestBody SelectAllConnectionDTO selectAllConnectionDTO) {
        return connectionDbService.selectAllConnection(token, selectAllConnectionDTO);
    }

    @PostMapping("/connection")
    public RestResult selectConnection(@RequestBody SelectConnectionDTO selectConnectionDTO) {
        return connectionDbService.selectConnection(selectConnectionDTO);
    }

    @RequestMapping("/add/connection")
    public RestResult addConnection(@RequestHeader("token")String token, @RequestBody AddConnectionDTO addConnectionDTO) {
        return connectionDbService.addConnection(token, addConnectionDTO);
    }

    @RequestMapping("/del/connection")
    public RestResult delConnection(@RequestBody DelConnectionDTO delConnectionDTO) {
        return connectionDbService.delConnection(delConnectionDTO);
    }

    @PostMapping("/test/connection")
    public RestResult testConnection(@RequestBody TestConnectionDTO testConnectionDTO) {
        return connectionDbService.testConnection(testConnectionDTO);
    }
}

